//
//  KZShopingListVC.swift
//  BoyeStore
//
//  Created by 朱凯 on 2018/6/27.
//  Copyright © 2018年 itboye. All rights reserved.
//

import UIKit

class KZShopingListVC: KZBaseViewControllerWithBack {

    var segmentBar = KZSegmentView()
    
    let table = UITableView()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        navigationItem.title = "购物列表"
        setupUI()
        
    }

    override func viewSafeAreaInsetsDidChange() {
        if #available(iOS 11.0, *) {
            table.snp.updateConstraints { (m) in
                m.bottom.equalTo(-view.safeAreaInsets.bottom)
            }
        }
    }
}

// MARK: ------ 创建视图
extension KZShopingListVC {
    
    private func setupUI() {
        
        
        // 搜索
        view.addSubview(segmentBar)
        segmentBar.config.backgroundColor = UIColor.white
        segmentBar.config.titleNormalColor = UIColor.lightGray
        segmentBar.config.titleSelectColor = kThemeColor
        segmentBar.config.indicatorColor = kThemeColor
        segmentBar.config.indicatorHeight = 2
        segmentBar.titles = ["免单商品", "返利商品"]
        segmentBar.snp.makeConstraints { (m) in
            m.left.right.equalTo(0)
            m.top.equalTo(0)
            m.height.equalTo(44)
        }
        

        // 列表
        table.delegate = self
        table.dataSource = self
        table.separatorStyle = .none
        table.estimatedRowHeight = 200
        table.rowHeight = UITableViewAutomaticDimension
        table.backgroundColor = kBgColor
        table.register(KZFreeProductCell.self, forCellReuseIdentifier: "cell")
        view.addSubview(table)
        table.snp.makeConstraints { (m) in
            m.left.right.equalTo(0)
            m.top.equalTo(segmentBar.snp.bottom)
            m.bottom.equalTo(0)
        }
        
        
    }
}

// MARK: ------ Table delegate
extension KZShopingListVC: UITableViewDelegate, UITableViewDataSource {
    
    // MARK: ------ tableview datasource
    func numberOfSections(in tableView: UITableView) -> Int {
        return 10
    }
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 1
    }
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        
        let cell: KZFreeProductCell = tableView.dequeueReusableCell(withIdentifier: "cell") as! KZFreeProductCell
        return cell
    }
    
    func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
        return 10
    }
    func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
        return UIView()
    }
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        
        let vc = KZProductDetailVC()
        self.navigationController?.pushViewController(vc, animated: true)
    }
    func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
        
    }
    func tableView(_ tableView: UITableView, editingStyleForRowAt indexPath: IndexPath) -> UITableViewCellEditingStyle {
        return .delete
    }
    func tableView(_ tableView: UITableView, titleForDeleteConfirmationButtonForRowAt indexPath: IndexPath) -> String? {
        return "删除"
    }
}

